package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingProjectPlanDto;
import com.zzyl.service.NursingProjectPlanService;
import com.zzyl.vo.NursingProjectPlanVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/nursing")
@Api(tags = "护理计划管理")
@Slf4j
public class NursingProjectPlanController extends BaseController {
    @Autowired
    NursingProjectPlanService nursingProjectPlanService;

    @GetMapping("/plan/search")
    @ApiOperation(value = "分页查询护理计划信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "页码", required = true, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "每页数量", required = true, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "planName", value = "计划名称", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "status", value = "状态", required = false, dataType = "int", paramType = "query"),
    })
    public ResponseResult<PageResponse<NursingProjectPlanVo>> selectByPage(Integer pageNum,
                                                                           Integer pageSize,
                                                                           String  name,
                                                                           Integer status
    ) {
        PageResponse<NursingProjectPlanVo> pageInfo = nursingProjectPlanService.selectByPage(pageNum, pageSize,name, status);
        return success(pageInfo);
    }

    //新增护理计划
    @PostMapping("/plan")
    @ApiOperation(value = "新增护理计划")
    public ResponseResult addNursingProjectPlan(@RequestBody NursingProjectPlanDto nursingProjectPlanDto) {
        nursingProjectPlanService.addNursingProjectPlan(nursingProjectPlanDto);
        return success();
    }

    //删除护理计划
    @DeleteMapping("/plan/{id}")
    @ApiOperation(value = "删除护理计划信息")
    public ResponseResult delete(@PathVariable Long id) {
        nursingProjectPlanService.deleteNursingProject(id);
        return success();
    }
    //根据id查询
    @GetMapping("/plan/{id}")
    @ApiOperation(value = "根据id查询护理计划信息")
    public ResponseResult<NursingProjectPlanVo> getById(@PathVariable Long id) {
        NursingProjectPlanVo nursingProjectPlanVo = nursingProjectPlanService.getById(id);
        return success(nursingProjectPlanVo);
    }
    //修改护理计划
    @PutMapping("/plan/{id}")
    @ApiOperation(value = "修改护理计划信息")
    public ResponseResult updateNursingProjectPlan(@RequestBody NursingProjectPlanDto nursingProjectPlanDto) {
        nursingProjectPlanService.upDateNursingProject(nursingProjectPlanDto);
        return success();
    }

    //启用禁用
    @PutMapping("/{id}/status/{status}")
    @ApiOperation(value = "启用禁用")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "id", required = true, dataType = "Long", paramType = "path"),
            @ApiImplicitParam(name = "status", value = "状态", required = true, dataType = "int", paramType = "path"),
    })
    public ResponseResult updateStatus(@PathVariable Long id, @PathVariable Integer status) {
        nursingProjectPlanService.updateStatus(id, status);
        return success();
    }

    //查询所有
    @GetMapping("/plan")
    @ApiOperation(value = "查询所有护理计划信息")
    public ResponseResult<NursingProjectPlanVo> getAll() {
        List<NursingProjectPlanVo> nursingProjectPlanVo = nursingProjectPlanService.getAll();
        return success(nursingProjectPlanVo);
    }
}
